<?php

namespace App\Repositories;
use Cache;
use App\Models\TestingUserEnterpriseRel;
use App\Repositories\Repository;

class TestingUserEnterpriseRelRepository extends Repository{

    static $tag = 'testing.user.enterprise.rel';

    public function store($data)
    {
        $res = TestingUserEnterpriseRel::create($data);
        return $res;
    }

    public function getByUidEid($uid, $eid, $organId=null)
    {
        $query = TestingUserEnterpriseRel::where('enterprice_id',$eid)->where('user_id',$uid);
        if($organId){
            $query = $query->where('organ_id',$organId);
        };
        $cate = $query->first();
        return $cate;
    }



    public function getList(){
        $key = getCacheKey('testing.cache_key.category.list');
        $list = $this->remember($key,function(){
            return TestingUserEnterpriseRel::all();
        });
        return $list;
    }

    public function getCateOptions(){
        $list = TestingUserEnterpriseRel::all();
        $data = [];
        if($list){
            $obj = array();
            foreach ($list as $key => $val){
                $obj['id'] = $val['id'];
                $obj['text'] = $val['name'];
                array_push($data,$obj);
            }
        }
        return $data;
    }


    public function model()
    {
        return app(TestingUserEnterpriseRel::class);
    }

    public function tag()
    {
        return self::$tag;
    }

    public function cacheTime()
    {
        return config('testing.common_cache_time');
    }
}